import "../css/JsonParse-DxFcpVJW.css";
import { defineComponent as Q, toRefs as W, ref as N, nextTick as ie, openBlock as C, createElementBlock as D, createVNode as p, unref as s, isRef as ee, withCtx as m, createElementVNode as h, createTextVNode as E, computed as te, watch as ue, onMounted as ae, normalizeStyle as de, toDisplayString as T, createCommentVNode as M, createBlock as H, pushScopeId as le, popScopeId as oe, reactive as Y, Fragment as pe, renderList as ce } from "vue";
import { a as U, r as ne, b as $, d as fe, Q as me, e as K, H as he, b1 as ve, c as ge, p as _e, aX as ye, B as be, C as A, aY as L, j as Ve, k as xe, a_ as ke, o as Ce, g as Se, f as Z } from "./vendor.CF2kwqqq.js";
import { C as Ne } from "./main.DDNsfpKl.js";
import { _ as X } from "./_plugin-vue_export-helper.CHgC5LLL.js";
import { d as z, e as De } from "./index.Bbfhrq76.js";
const Ee = [
  "boolean",
  "data",
  "double",
  "float",
  "int",
  "long",
  "timestamp",
  "varchar",
  "decimal",
  "string",
  "date",
  "array",
  "MAP",
  "RECORD"
], $e = (e) => new Promise((b, _) => {
  fetch(e).then(async (v) => {
    const g = v.ok;
    let a;
    try {
      a = (await v.text()).trim(), /^(\{|\[).*?(\]|\})$/.test(a) && (a = JSON.parse(a));
    } catch (l) {
      console.log(l);
    }
    g ? b(a) : (U.warning(a), _(a));
  }).catch((v) => _(v));
});
function F(e, b = "$", _ = !0) {
  let v = [], g = [];
  if (Array.isArray(e)) {
    let a = {
      name: "[",
      value: "",
      children: [],
      isChecked: !1,
      type: "string",
      path: b,
      leftTag: "[",
      rightTag: "]",
      isSymbol: !0,
      isNifi: !0
    };
    const l = F(e[e.length - 1], `${a.path}[*]`);
    a.children.push(...l.result), g.push(...l.allPaths), v.push(a), g.push(a.path);
  } else if (Object.prototype.toString.call(e) === "[object Object]") {
    _ && v.push({
      name: "{",
      value: "",
      children: [],
      isChecked: !1,
      type: "string",
      path: b,
      leftTag: "{",
      rightTag: "}",
      isSymbol: !0,
      isNifi: !0
    });
    for (let a in e)
      if (e.hasOwnProperty(a)) {
        let l = {
          name: a,
          value: typeof e[a] != "object" && typeof e[a] !== null ? e[a] : "",
          children: [],
          isChecked: !1,
          type: "string",
          path: b,
          leftTag: "",
          rightTag: "",
          isNifi: !0
        };
        if (Array.isArray(e[a])) {
          l.leftTag = "[", l.rightTag = "]", l.path += `.${a}`, e[a].format && (l.format = e[a].format), G(l.value) && (l.type = "int");
          const d = F(
            e[a][e[a].length - 1],
            `${l.path}[*]`
          );
          l.children.push(...d.result), g.push(...d.allPaths);
        } else if (typeof e[a] == "object" && e[a] !== null) {
          l.leftTag = "{", l.rightTag = "}", l.path += `.${a}`, e[a].format && (l.format = e[a].format), G(l.value) && (l.type = "int");
          const d = F(e[a], `${b}.${a}`, !1);
          l.children.push(...d.result), g.push(...d.allPaths);
        } else
          l.path += `.${a}`, G(l.value) && (l.type = "int");
        g.push(l.path), _ ? v[0].children.push(l) : v.push(l);
      }
  }
  return { result: v, allPaths: g };
}
function se(e) {
  try {
    return JSON.parse(e), !0;
  } catch {
    return !1;
  }
}
function G(e) {
  return !isNaN(parseFloat(e)) && isFinite(e);
}
function we(e, b, _ = "path", v = "name") {
  let g = e.filter((u) => !u.isNifi), a = [...b, ...g];
  for (let u = 0; u < e.length; u++) {
    const i = e[u];
    for (let c = 0; c < a.length; c++) {
      const k = a[c];
      i[_] === k[_] && (a[c].name = i.name);
    }
  }
  const l = /* @__PURE__ */ new Map(), d = [];
  for (let u of a) {
    const i = u[v];
    if (!l.get(i))
      l.set(i, 1), d.push(u);
    else {
      for (; l.get(`${i}_${l.get(i)}`); )
        l.set(i, l.get(i) + 1);
      let c = { ...u, name: `${i}_${l.get(i)}` };
      l.set(c.name, 1), d.push(c);
    }
  }
  return d;
}
const Oe = { "h-450px": "" }, Te = { class: "node_footer" }, Fe = /* @__PURE__ */ Q({
  __name: "CodeDialog",
  props: {
    modelValue: { type: Boolean },
    jsonData: {}
  },
  emits: ["update:modelValue", "updateCode"],
  setup(e, { emit: b }) {
    const _ = b, v = e, { modelValue: g, jsonData: a } = W(v), l = N();
    a.value && ie(() => {
      var i;
      (i = l.value) == null || i.insertValue(a.value);
    });
    const d = () => {
      _("update:modelValue", !1);
    }, u = () => {
      var k;
      let i = (k = l.value) == null ? void 0 : k.getValue();
      se(i) ? (_("updateCode", i), d()) : U.error("JSON数据不规范，无法更新，请修改后重试");
    };
    return (i, c) => (C(), D("div", null, [
      p(s(ne), {
        modelValue: s(g),
        "onUpdate:modelValue": c[0] || (c[0] = (k) => ee(g) ? g.value = k : null),
        title: "自定义节点",
        "destroy-on-close": "",
        "before-close": d
      }, {
        default: m(() => [
          h("div", Oe, [
            p(Ne, {
              ref_key: "codeEditorRef",
              ref: l
            }, null, 512)
          ]),
          h("div", Te, [
            p(s($), { onClick: d }, {
              default: m(() => [
                E("取消")
              ]),
              _: 1
            }),
            p(s($), {
              type: "primary",
              onClick: u
            }, {
              default: m(() => [
                E("更新")
              ]),
              _: 1
            })
          ])
        ]),
        _: 1
      }, 8, ["modelValue"])
    ]));
  }
}), Ie = /* @__PURE__ */ X(Fe, [["__scopeId", "data-v-a85a649d"]]), re = (e) => (le("data-v-4435789a"), e = e(), oe(), e), Pe = { class: "nifi-json-parsing-node" }, Re = {
  flex: "",
  "items-center": "",
  "h-30px": "",
  "px-12px": "",
  "py-5px": "",
  "rounded-4px": "",
  "m-b-12px": "",
  class: "bg-#E5EFFF"
}, Ue = {
  flex: "",
  "justify-between": "",
  "items-center": ""
}, Je = /* @__PURE__ */ re(() => /* @__PURE__ */ h("span", { "font-semibold": "" }, "选择节点", -1)), Be = {
  flex: "",
  "gap-x-2px": ""
}, Me = {
  key: 0,
  flex: "",
  "gap-x-4px": ""
}, qe = /* @__PURE__ */ re(() => /* @__PURE__ */ h("span", null, ":", -1)), Ae = { class: "color-#091e4077" }, je = { key: 0 }, Le = {
  key: 1,
  "px-4px": ""
}, ze = { key: 0 }, Ge = { class: "node_footer" }, He = /* @__PURE__ */ Q({
  __name: "Dialog",
  props: {
    modelValue: { type: Boolean },
    connectionId: {},
    api: {},
    nodeList: {}
  },
  emits: ["update:modelValue", "handleUpdateValue"],
  setup(e, { emit: b }) {
    const _ = b, v = e, { modelValue: g, connectionId: a, api: l, nodeList: d } = W(v), u = N(""), i = N([]), c = N([]), k = te(() => (t) => c.value.findIndex((n) => n.path === t.path) > -1), V = (t, o) => t ? o.name.includes(t) : !0, w = async () => {
      var j, q;
      let t = `/nifi-api/flowfile-queues/${a.value}/listing-requests`, o = await ((j = l.value) == null ? void 0 : j.post(t));
      const n = o.listingRequest.id;
      t = t + "/" + n;
      do
        o = await ((q = l.value) == null ? void 0 : q.get(t)), await new Promise((B) => setTimeout(() => B(!0), 500));
      while (o.listingRequest.finished == !1);
      const f = o.listingRequest.flowFileSummaries || [];
      if (f.length == 0)
        U.info("暂无json数据");
      else {
        let B = f[0].uri.replace(/^http(.*?)\/nifi-api/, "/nifi-api");
        J(B);
      }
    }, J = async (t) => {
      const o = `${t}/content`;
      let n = await $e(o), f = typeof n == "object" ? JSON.stringify(n, null, 2).trim() : n;
      if (!se(f)) {
        U.error("JSON数据不规范，请修改后重试");
        return;
      }
      i.value = F(n).result, u.value = f;
      let q = F(n).allPaths;
      c.value = d.value.filter((B) => q.includes(B.path));
    }, S = N(), I = {
      children: "children",
      name: "name"
    }, P = (t) => {
      if (t.isSymbol)
        return;
      let o = c.value.findIndex((n) => n.path === t.path);
      o === -1 ? c.value.push(t) : c.value.splice(o, 1);
    }, x = N(!1), R = (t) => {
      let o = typeof t == "string" && t !== null ? JSON.parse(t) : [];
      i.value = F(o).result;
      let n = F(o).allPaths;
      u.value = t, c.value = c.value.filter((f) => n.includes(f.path));
    }, O = () => {
      _("update:modelValue", !1);
    }, r = () => {
      _("handleUpdateValue", c.value), O();
    }, y = N("");
    return ue(y, (t) => {
      S.value.filter(t);
    }), ae(() => {
      try {
        w();
      } catch {
      } finally {
      }
    }), (t, o) => (C(), D("div", Pe, [
      p(s(ne), {
        modelValue: s(g),
        "onUpdate:modelValue": o[3] || (o[3] = (n) => ee(g) ? g.value = n : null),
        title: "选择JSON节点",
        "destroy-on-close": "",
        "before-close": O
      }, {
        default: m(() => [
          h("div", null, [
            h("div", Re, [
              p(s(fe), { "m-r-8px": "" }, {
                default: m(() => [
                  p(s(me))
                ]),
                _: 1
              }),
              E(" 节点仅对应“绝对路径”的JSON解析路径，无法与“相对路径”匹配 ")
            ]),
            h("div", Ue, [
              Je,
              h("div", null, [
                p(s($), {
                  type: "primary",
                  text: "",
                  "p-0": "",
                  onClick: w
                }, {
                  default: m(() => [
                    E(" 重新获取 ")
                  ]),
                  _: 1
                }),
                p(s($), {
                  type: "primary",
                  text: "",
                  "p-0": "",
                  onClick: o[0] || (o[0] = (n) => x.value = !0)
                }, {
                  default: m(() => [
                    E(" 自定义 ")
                  ]),
                  _: 1
                })
              ])
            ]),
            p(s(K), {
              modelValue: y.value,
              "onUpdate:modelValue": o[1] || (o[1] = (n) => y.value = n),
              placeholder: "搜索",
              "prefix-icon": s(he),
              style: { width: "240px" }
            }, null, 8, ["modelValue", "prefix-icon"]),
            p(s(ve), {
              ref_key: "treeRef",
              ref: S,
              data: i.value,
              props: I,
              "highlight-current": "",
              "default-expand-all": "",
              "node-key": "path",
              "expand-on-click-node": !1,
              "filter-node-method": V,
              onNodeClick: P
            }, {
              default: m(({ node: n, data: f }) => [
                h("div", Be, [
                  f.isSymbol ? (C(), D("div", Le, [
                    h("span", null, T(f.leftTag), 1),
                    !n.expanded && f.rightTag ? (C(), D("span", ze, "..." + T(f.rightTag), 1)) : M("", !0)
                  ])) : (C(), D("div", Me, [
                    p(s(ge), {
                      content: `生成解析路径：${f.path}`,
                      placement: "top"
                    }, {
                      default: m(() => [
                        h("div", {
                          "px-4px": "",
                          style: de({
                            backgroundColor: k.value(f) ? "#7fa6c5" : "#EEF1F6",
                            color: k.value(f) ? "#fff" : "#606266"
                          })
                        }, [
                          h("span", null, T(f.name), 1)
                        ], 4)
                      ]),
                      _: 2
                    }, 1032, ["content"]),
                    qe,
                    h("span", Ae, T(f.value), 1),
                    h("div", null, [
                      h("span", null, T(f.leftTag), 1),
                      n.expanded ? M("", !0) : (C(), D("span", je, "..." + T(f.rightTag), 1))
                    ])
                  ]))
                ])
              ]),
              _: 1
            }, 8, ["data"])
          ]),
          c.value.length > 0 ? (C(), D("div", {
            key: 0,
            "cursor-pointer": "",
            class: "text-#7fa6c5",
            onClick: o[2] || (o[2] = (n) => c.value.length = 0)
          }, " 取消选中（" + T(c.value.length) + "）个节点 ", 1)) : M("", !0),
          h("div", Ge, [
            p(s($), { onClick: O }, {
              default: m(() => [
                E("取消")
              ]),
              _: 1
            }),
            p(s($), {
              type: "primary",
              onClick: r
            }, {
              default: m(() => [
                E("保存")
              ]),
              _: 1
            })
          ])
        ]),
        _: 1
      }, 8, ["modelValue"]),
      x.value ? (C(), H(Ie, {
        key: 0,
        modelValue: x.value,
        "onUpdate:modelValue": o[4] || (o[4] = (n) => x.value = n),
        "json-data": u.value,
        onUpdateCode: R
      }, null, 8, ["modelValue", "json-data"])) : M("", !0)
    ]));
  }
}), Ke = /* @__PURE__ */ X(He, [["__scopeId", "data-v-4435789a"]]), Qe = (e) => (le("data-v-d033c4e2"), e = e(), oe(), e), We = { class: "nifi-json-parsing" }, Xe = { class: "json_container" }, Ye = /* @__PURE__ */ Qe(() => /* @__PURE__ */ h("span", null, "解析JSON数据", -1)), Ze = {
  flex: "",
  "justify-between": ""
}, et = { class: "json_table_wrapper" }, tt = { class: "json_table_content" }, at = /* @__PURE__ */ Q({
  __name: "index",
  props: {
    formdata: {},
    graphShadow: {},
    inputV: {},
    step: {},
    api: {}
  },
  setup(e) {
    const b = e, { formdata: _, graphShadow: v, step: g, api: a, inputV: l } = W(b);
    let d = te(() => g.value === "running");
    const u = N(!1), i = N(""), c = () => {
      if (i.value = [...v.value.get(_.value.id).inCells][0], !i.value) {
        U.error("暂无上游算子，请进行连接");
        return;
      }
      u.value = !0;
    }, k = (r) => {
      V.tableData = we(V.tableData, r);
    }, V = Y({
      tableData: [...l.value]
    }), w = N(), S = Y({
      name: [
        {
          // required: true,
          // message: "解析后字段名称不能为空",
          validator: (r, y, t) => {
            if (y === "")
              return t(new Error("字段名不能为空"));
            if (V.tableData.filter((n) => n.name === y).length > 1)
              return t(new Error("不可与其他字段重名"));
            t();
          },
          trigger: "blur"
        }
      ],
      path: [
        {
          required: !0,
          message: "解析路径不能为空",
          trigger: "blur"
        }
      ],
      type: [
        {
          required: !0,
          message: "字段类型不能为空",
          trigger: "change"
        }
      ]
    }), I = () => {
      V.tableData.push({
        name: "",
        path: "",
        type: "",
        value: ""
      });
    }, P = (r) => {
      V.tableData.splice(r, 1);
    }, x = (r, y) => {
      if (r) {
        if (r.prompt = "", r.visible = !1, r.name === "") {
          r.prompt = "字段名不能为空", r.visible = !0;
          return;
        }
        for (let t = 0; t < V.tableData.length; t++)
          if (V.tableData[t].name === r.name && t !== y) {
            r.prompt = "不可与其他字段重名", r.visible = !0;
            return;
          }
        r.prompt = "", r.visible = !1;
      }
    }, R = (r) => {
      r && (r.prompt = "", r.visible = !1);
    };
    ae(() => {
      v.value.set(_.value.id, "checkForm", O), v.value.set(_.value.id, "form", V);
    });
    const O = () => new Promise((r) => {
      var y;
      (y = w.value) == null || y.validate((t, o) => {
        t ? r(V.tableData) : (U.error(Object.values({ ...o })[0][0].message), r(!1));
      });
    });
    return (r, y) => (C(), D("div", We, [
      h("div", Xe, [
        Ye,
        h("div", null, [
          h("div", Ze, [
            p(s($), {
              type: "primary",
              text: "",
              "p-0": "",
              onClick: c
            }, {
              default: m(() => [
                E(" 选择JSON节点 ")
              ]),
              _: 1
            }),
            p(s($), {
              type: "primary",
              text: "",
              "p-0": "",
              icon: s(_e),
              onClick: I
            }, {
              default: m(() => [
                E(" 添加字段 ")
              ]),
              _: 1
            }, 8, ["icon"])
          ]),
          h("div", et, [
            h("div", tt, [
              p(s(ye), {
                ref_key: "formRef",
                ref: w,
                model: V,
                rules: S,
                disabled: s(d)
              }, {
                default: m(() => [
                  p(s(be), {
                    data: V.tableData,
                    border: "",
                    style: { "margin-top": "20px" }
                  }, {
                    default: m(() => [
                      p(s(A), { label: "解析后字段名称" }, {
                        default: m(({ $index: t, row: o }) => [
                          p(s(L), {
                            prop: "tableData." + t + ".name",
                            rules: S.name
                          }, {
                            default: m(() => [
                              p(s(K), {
                                modelValue: o.name,
                                "onUpdate:modelValue": (n) => o.name = n,
                                placeholder: "请输入",
                                clearable: "",
                                onBlur: (n) => {
                                  var f;
                                  return o.name = (f = n.target) == null ? void 0 : f.value.trim();
                                },
                                onMouseenter: (n) => x(o, t),
                                onMouseleave: (n) => R(o)
                              }, null, 8, ["modelValue", "onUpdate:modelValue", "onBlur", "onMouseenter", "onMouseleave"])
                            ]),
                            _: 2
                          }, 1032, ["prop", "rules"])
                        ]),
                        _: 1
                      }),
                      p(s(A), { label: "解析路径" }, {
                        default: m(({ $index: t, row: o }) => [
                          p(s(L), {
                            prop: "tableData." + t + ".path",
                            rules: S.path
                          }, {
                            default: m(() => [
                              p(s(K), {
                                modelValue: o.path,
                                "onUpdate:modelValue": (n) => o.path = n,
                                placeholder: "请输入",
                                clearable: "",
                                onBlur: (n) => {
                                  var f;
                                  return o.path = (f = n.target) == null ? void 0 : f.value.trim();
                                }
                              }, null, 8, ["modelValue", "onUpdate:modelValue", "onBlur"])
                            ]),
                            _: 2
                          }, 1032, ["prop", "rules"])
                        ]),
                        _: 1
                      }),
                      p(s(A), { label: "字段类型" }, {
                        default: m(({ $index: t, row: o }) => [
                          p(s(L), {
                            prop: "tableData." + t + ".type",
                            rules: S.type
                          }, {
                            default: m(() => [
                              p(s(Ve), {
                                modelValue: o.type,
                                "onUpdate:modelValue": (n) => o.type = n,
                                placeholder: "请输入",
                                filterable: "",
                                clearable: "",
                                "popper-class": "select_popper"
                              }, {
                                default: m(() => [
                                  (C(!0), D(pe, null, ce(s(Ee), (n) => (C(), H(s(xe), {
                                    key: n,
                                    label: n,
                                    value: n
                                  }, null, 8, ["label", "value"]))), 128))
                                ]),
                                _: 2
                              }, 1032, ["modelValue", "onUpdate:modelValue"])
                            ]),
                            _: 2
                          }, 1032, ["prop", "rules"])
                        ]),
                        _: 1
                      }),
                      p(s(A), { label: "操作" }, {
                        default: m(({ $index: t }) => [
                          p(s(ke), {
                            "hide-icon": "",
                            "confirm-button-text": "确定",
                            "cancel-button-text": "取消",
                            "icon-color": "#626AEF",
                            title: "确认删除？",
                            onConfirm: (o) => P(t)
                          }, {
                            reference: m(() => [
                              p(s($), {
                                text: "",
                                type: "primary",
                                title: "删除",
                                icon: s(Ce),
                                "m-b-18px": ""
                              }, null, 8, ["icon"])
                            ]),
                            _: 2
                          }, 1032, ["onConfirm"])
                        ]),
                        _: 1
                      })
                    ]),
                    _: 1
                  }, 8, ["data"])
                ]),
                _: 1
              }, 8, ["model", "rules", "disabled"])
            ])
          ])
        ])
      ]),
      u.value ? (C(), H(Ke, {
        key: 0,
        modelValue: u.value,
        "onUpdate:modelValue": y[0] || (y[0] = (t) => u.value = t),
        "connection-id": i.value,
        "node-list": V.tableData,
        api: s(a),
        onHandleUpdateValue: k
      }, null, 8, ["modelValue", "connection-id", "node-list", "api"])) : M("", !0)
    ]));
  }
}), lt = /* @__PURE__ */ X(at, [["__scopeId", "data-v-d033c4e2"]]), dt = () => {
  let e = [], b = null;
  return { name: "org.apache.nifi.column.processors.JsonParse_1_0", excludeKeys: ["json-input"], selfFormColumn: [
    {
      tag: lt,
      ":formdata": "formData",
      setup({ params: d }) {
        return {
          inputV: e,
          graphShadow: d.graphShadow,
          step: d.step.value,
          api: b
        };
      },
      ":inputV": "inputV",
      ":graphShadow": "graphShadow",
      ":step": "step",
      ":api": "api"
    }
  ], hooksOpen: (d, u) => {
    e = [], b = u.api;
    let i = u.event.source.get(d.id).component;
    e = z(Se(i, 'config.properties["json-input"]'));
  }, hooksSubmit: (d, u) => {
    var V, w, J, S, I, P;
    De(d, u);
    let i = ((V = u.event.shadow) == null ? void 0 : V.get(d.id).form.tableData) ?? [], c = i.filter(
      (x) => !x.name || !x.path || !x.type
    ), k = new Set(i.map((x) => x.name));
    if (c.length > 0)
      throw (w = u.event.shadow) == null || w.get(d.id).checkForm(), new Error("不能为空");
    if (k.size !== i.length)
      throw (J = u.event.shadow) == null || J.get(d.id).checkForm(), new Error("不可与其他字段重名");
    {
      let x = (S = u.event.form) == null ? void 0 : S.data.value[d.id].config.properties, R = [], O = [];
      i.forEach((r) => {
        let y = { name: r.name, type: r.type };
        R.push(
          r.isNifi ? { ...y, path: r.path, isNifi: r.isNifi } : { ...y, path: r.path }
        ), O.push(
          r.format ? { ...y, format: r.format, originalValue: r.name } : { ...y, originalValue: r.name }
        );
      }), Z(x, "json-input", z(R)), Z(x, "output-param", z(O)), (I = u.event.shadow) == null || delete I.get(d.id).form, (P = u.event.shadow) == null || delete P.get(d.id).checkForm;
    }
  } };
};
export {
  dt as default
};
